package fh.app4stud.mensa.data;

import java.math.BigDecimal;

/**
 * Created by IntelliJ IDEA. User: ifi Date: 22.04.11 Time: 00:33 To change this
 * template use File | Settings | File Templates.
 */
public class RestaurantLocation {

	String city;
	String houseNumber;
	String locationName;
	String streetName;
	String ZIPCode;
	double longitude;
	double latitude;

	BigDecimal distanceFromCurrentLocation;

	public RestaurantLocation(String _city, String _houseNumber,
			String _locationName, String _streetName, String _ZIPCode,
			double _longitude, double _latitude) {
		this.city = _city;
		this.houseNumber = _houseNumber;
		this.locationName = _locationName;
		this.streetName = _streetName;
		this.ZIPCode = _ZIPCode;
		this.longitude = _longitude;
		this.latitude = _latitude;
	}

	public RestaurantLocation(String _city, String _houseNumber,
			String _locationName, String _streetName, String _ZIPCode,
			double _longitude, double _latitude, double currentLongitude,
			double currentLatitude) {
		this.city = _city;
		this.houseNumber = _houseNumber;
		this.locationName = _locationName;
		this.streetName = _streetName;
		this.ZIPCode = _ZIPCode;
		this.longitude = _longitude;
		this.latitude = _latitude;

		this.distanceFromCurrentLocation = distance(_latitude, _longitude,
				currentLatitude, currentLongitude);

	}

	/**
	 * Source : http://www.zipcodeworld.com/samples/distance.java.html
	 */
	private BigDecimal distance(double lat1, double lon1, double lat2,
			double lon2) {
		double theta = lon1 - lon2;
		double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
				+ Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2))
				* Math.cos(deg2rad(theta));
		dist = Math.acos(dist);
		dist = rad2deg(dist);
		dist = dist * 60 * 1.1515;
		// calculate kilometers
		dist = dist * 1.609344;
		// calculate in miles : dist = dist * 0.8684;
		BigDecimal ret = new BigDecimal(dist);
		return (ret);
	}

	/**
	 * Source : http://www.zipcodeworld.com/samples/distance.java.html
	 */
	private double deg2rad(double deg) {
		return (deg * Math.PI / 180.0);
	}

	/**
	 * Source : http://www.zipcodeworld.com/samples/distance.java.html
	 */
	private double rad2deg(double rad) {
		return (rad * 180.0 / Math.PI);
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getHouseNumber() {
		return houseNumber;
	}

	public void setHouseNumber(String houseNumber) {
		this.houseNumber = houseNumber;
	}

	public String getLocationName() {
		return locationName;
	}

	public void setLocationName(String locationName) {
		this.locationName = locationName;
	}

	public String getStreetName() {
		return streetName;
	}

	public void setStreetName(String streetName) {
		this.streetName = streetName;
	}

	public String getZIPCode() {
		return ZIPCode;
	}

	public void setZIPCode(String ZIPCode) {
		this.ZIPCode = ZIPCode;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public BigDecimal getDistanceFromCurrentLocation() {
		return distanceFromCurrentLocation;
	}

	public void setDistanceFromCurrentLocation(
			BigDecimal distanceFromCurrentLocation) {
		this.distanceFromCurrentLocation = distanceFromCurrentLocation;
	}
}
